package com.wanbangee.marksystem.service.imp;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.wanbangee.marksystem.dao.StatisticsAverageRankingDao;
import com.wanbangee.marksystem.entities.StatisticsAverageRanking;
import com.wanbangee.marksystem.service.QueryOnePointAndThreeRateRankingService;

@Service
public class QueryOnePointAndThreeRateRankingServiceImp implements QueryOnePointAndThreeRateRankingService {

	@Autowired
	private StatisticsAverageRankingDao statisticsAverageRankingDao;

	@Override
	public Map<String, Object> selectOnePointAndThreeRateRanking(Integer examId, Integer subId, Integer claId) {
		Map<String, Object> map = new HashMap<>();
		//查询考试Id
		List<Integer> examList = this.statisticsAverageRankingDao.selectExamIdByClaIdAndSubId(examId,claId, subId);
		List<Map> excellentRateRankingList = new ArrayList<>();
		List<Map> goodRateRankingList = new ArrayList<>();
		List<Map> passRateRankingList = new ArrayList<>();
		for(int i=0;i<examList.size();i++) {
			excellentRateRankingList.add(this.statisticsAverageRankingDao.selectExamNmAndExcellentRateRanking(examList.get(i), subId, claId));
			goodRateRankingList.add(this.statisticsAverageRankingDao.selectExamNmAndGoodRateRanking(examList.get(i), claId, subId));
			passRateRankingList.add(this.statisticsAverageRankingDao.selectExamNmAndPassRateRanking(examList.get(i), claId, subId));
		}
		//查询平均分年级排名，本次考试班级平均分，年级平均分，历次平均分排名
		map.put("averageMap", this.statisticsAverageRankingDao.selectAverageAndRankingAndGradeAvg(examId, subId, claId));
		map.put("averageRankingMap", this.statisticsAverageRankingDao.selectExamNmAndRanking(examId, subId, claId));
		//查询优秀率年级排名，本次考试班级优秀率，年级优秀率，历次优秀率排名
		map.put("excellentRateMap", this.statisticsAverageRankingDao.selectExcellentRateAndExceGradeRankAndGradeAvgRanking(examId, subId, claId));
		map.put("excellentRateRankingList", excellentRateRankingList);
		//查询良好率年级排名，本次考试班级良好率，年级良好率，历次良好率排名
		map.put("goodRateMap", this.statisticsAverageRankingDao.selectGoodRateAndGoodGradeRankAndGradeAvgRanking(examId, claId, subId));
		map.put("goodRateRankingList", goodRateRankingList);
		//查询及格率年级排名，本次考试班级及格率，年级及格率，历次及格率排名
		map.put("passRateMap", this.statisticsAverageRankingDao.selectPassRateAndPassGradeRankAndPassAvgRanking(examId, claId, subId));
		map.put("passRateRankingList", passRateRankingList);
		return map;
	}
	
}
